package cs340omega;

import java.io.*;
import java.lang.reflect.*;

//This is a test driver for the Object Database and creating Commands
//	NOT NEEDED FOR NORMAL EXECUTION

public class Driver
{

	public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException,
												   InvocationTargetException, ClassNotFoundException,
												   IOException
	{
		final int SERVER_PORT = 3000;
		final String LOCALHOST = "127.0.0.1";
		
		ObjectDB objects = new ObjectDB();
		Test1 test = new Test1();
		GlobalID id = objects.get(LOCALHOST, SERVER_PORT, 0);
		objects.put(id, test);

		Object[] myargs = new Object[2];
		
		int tasks = 5;
		myargs[0] = tasks;
		myargs[1] = " more to do.";
		
		Class<?> thetest = objects.get(id).getClass();
		Class<?> a = int.class;
		Class<?> b = Class.forName("java.lang.String");
		Command command;
		try
		{
			command = new Command(id, "little", new Class[]{a, b}, myargs, false);
		}
		catch (NumberFormatException e)
		{
			System.out.println("Command is invalid: " + e.getMessage());
			return;
		}
		
		Method theMethod = thetest.getMethod("little", new Class[] {a, b});
	
		//Debug to print out Method to be invoked
		System.out.println("Method name: " + theMethod.getName());

		//Invoke Method and print return value
		System.out.println("Method return value: " 
							+ theMethod.invoke(objects.get(id), myargs));
		System.out.println("Command return value: " + command.invoke(objects.get(id)));
		
		MachineID machineID;
		machineID = new MachineID("192.168.1.7");
		System.out.println(machineID.getHost() + " " + machineID.getIP());
	
		//test = new Test();
		//ProxyConstructor.createProxy(test.getClass().getName());
		
		//Test1 test1 = new Test1();
		//ProxyConstructor.createProxy(test1.getClass().getName());
		
		objects.finalize();

	}

}
